package com.test.spcloud.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.zaxxer.hikari.HikariDataSource;

@Configuration
public class DataSourceConfiguration {
    // Hikari 连接池
  @Bean(name = "dataSource")
  public DataSource dataSource(@Autowired Environment environment) {
      HikariDataSource ds = new HikariDataSource();
      ds.setJdbcUrl(environment.getProperty("spring.datasource.url"));
      ds.setUsername(environment.getProperty("spring.datasource.username"));
      ds.setPassword(environment.getProperty("spring.datasource.password"));
      ds.setDriverClassName(environment.getProperty("spring.datasource.driver-class-name"));
      return ds;
  }
}
